package com.ztesoft.ossup.report.dao;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class JdbcTemplateDao {
	
	@Autowired
	JdbcTemplate jdbcTemplate;
	
	public List<Map<String, Object>> getConditionValues(String sql) throws Exception{		
		return jdbcTemplate.queryForList(sql);
	}
	
	public List<Map<String, Object>> getDataByPage(String sql,int offset, int limit) throws Exception{
		int startNum = offset + 1;
		int endNum = offset + limit ;
		sql = "select * from (select rownum as idx,tt.* from ( " +sql + " ) tt ) ttt where ttt.idx between "+ startNum +" and "+endNum;		 
		return jdbcTemplate.queryForList(sql);
	}
	
	public Long getDataSize(String sql) throws Exception{
		sql = "select count(1) from ( " +sql + " )";
		return jdbcTemplate.queryForLong(sql);
	}
	
	public List<Map<String, Object>> getData(String sql) throws Exception{		
		return jdbcTemplate.queryForList(sql);
	}

}
